package com.huluobo.a2302mdmdemo.pages

import android.window.SplashScreen
import androidx.compose.foundation.ExperimentalFoundationApi
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxHeight
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.pager.HorizontalPager
import androidx.compose.foundation.pager.rememberPagerState
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.layout.ContentScale
import androidx.compose.ui.unit.dp
import androidx.navigation.NavHostController
import coil.compose.AsyncImage
import com.huluobo.lib_base.RoutePath

/**
 *  Created by LC on 2025/7/22.
 *  引导页
 */

@OptIn(ExperimentalFoundationApi::class)
@Composable
fun SplashPage(navHostController: NavHostController) {
    val list = listOf(
        "https://img2.baidu.com/it/u=1134184213,2435039814&fm=253&fmt=auto?w=1062&h=800",
        "https://img1.baidu.com/it/u=2693733305,4035903587&fm=253&app=138&size=w931&n=0&f=JPEG&fmt=auto?sec=1729184400&t=92694ac7a4bb0b4a405af0e28c18cd82",
        "https://img0.baidu.com/it/u=540669065,2162680038&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1729184400&t=3adc1ec41d0f0d8ac469eb88eb19c531",
        "https://img2.baidu.com/it/u=553712968,3437602612&fm=253&app=120&size=w931&n=0&f=JPEG&fmt=auto?sec=1729184400&t=280fc51f8b1c0619aedbe9c1d5ce9895",
        "https://img0.baidu.com/it/u=1677400077,1401427640&fm=253&fmt=auto?w=679&h=1216"
    )

    //保存轮播图页面的下标
    val pageState = rememberPagerState {
        5
    }

    HorizontalPager(state = pageState, modifier = Modifier.fillMaxHeight()) { index ->
        Box(modifier = Modifier.fillMaxSize(), contentAlignment = Alignment.BottomCenter) {
            AsyncImage(
                model = list[index],
                contentDescription = "",
                modifier = Modifier.fillMaxHeight(),
                contentScale = ContentScale.Crop
            )
            if (pageState.currentPage == 4) {
                Button(onClick = {
                    //跳转到首页
                    navHostController.navigate(RoutePath.MAIN)
                }, modifier = Modifier.padding(bottom = 50.dp)) {
                    Text(text = "跳过")
                }
            }
        }
    }
}